/**
 * 替换默认的typeorm日志
 */
import { Injectable } from "@nestjs/common";
import { Logger, QueryRunner } from "typeorm"
import { Logger as WinstonLogger } from "winston";
import  logger  from '../../shared/winston.config';

@Injectable()
export class CustomTypeOrmLogger implements Logger {
    private readonly logger: WinstonLogger;
    constructor() {
        this.logger = logger;
    }
    logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner) {
        // throw new Error("Method not implemented.");
        // console.log('新log ', query, parameters);
        this.logger.info(`${query} parameters: ${parameters}`);
    }
    logQueryError(error: string | Error, query: string, parameters?: any[], queryRunner?: QueryRunner) {
        this.logger.info(`${query} parameters: ${parameters} ${error}`);
    }
    logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner) {
        this.logger.info(`${query} parameters: ${parameters} 执行时间：${time}`);
        
    }
    logSchemaBuild(message: string, queryRunner?: QueryRunner) {
        this.logger.info(`${message} `);
        
    }
    logMigration(message: string, queryRunner?: QueryRunner) {
        this.logger.info(`${message}`);
    }
    log(level: "info" | "log" | "warn", message: any, queryRunner?: QueryRunner) {
        // this.logger.info(`${message} `);
    }
    // implement all methods from logger class
}